import React, { Component } from 'react';
import { connect } from 'react-redux'
import { actionCreator,mapStateToProps,mapDispatchToProps } from '../../store/actions'
class Item extends Component {
  changeDone = (ev) => {
    let { data } = this.props
    let obj = {
      id:data.id,
      todo: data.todo,
      done:ev.target.checked
    }
    this.props.check(actionCreator('check',obj))
  }
  deleteSelect = (ev) => {
    let { data } = this.props
    this.props.deleteSelect(actionCreator('deleteSelect',data))
  }
  render() {
    let { data }=this.props
    return (
      <li>
        <input type="checkbox" checked={data.done} onChange={this.changeDone} /><label>{data.todo}</label>
        <button className='btn-del' onClick={ this.deleteSelect }>删除</button>
      </li>
    )
  }
}

export default connect(mapStateToProps,mapDispatchToProps)(Item);